<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/5
 * Time: 17:48
 */

namespace app\modules\api\controllers;

use yii\web\Controller;
use app\lib\BaseFunction;

class UploadController extends Controller
{
    public $enableCsrfValidation = false;

    /**
     *
     */
    public function actionImg()
    {
        $file = $_FILES['file'];
        if ($this->checkImg($file['type']))
        {
            $path = BaseFunction::upload($file);
            echo json_encode(['response'=>'success','linkProps'=>$path]);
        }

    }

    /**
     * @param $type
     * @return bool
     */
    public function checkImg($type)
    {
        $acceptArray = ['image/png','image/jpeg','image/jpg'];
        if (in_array($type,$acceptArray)) {
            return true;
        }
        return false;
    }
}